package com.ygqh.baby.controller.mobile;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.service.YgProductSecondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/mobile/productsecond")
public class YgProductSecondController extends BaseController {

    @Autowired
    private YgProductSecondService ygProductSecondService;

    /**
     * 获取指定日期秒杀商品信息
     *
     * @param callback
     * @param specifyDate 指定日期（不指定时，默认为当前日期）
     * @return
     */
    @RequestMapping("findProductListBySecond")
    @ResponseBody
    public JSONPObject findProductListBySecond(String callback, Date specifyDate) {
        return new JSONPObject(callback, Message.success(ygProductSecondService.findBySpecifyDate(specifyDate)));
    }

    /**
     * 获取指定商品的秒杀日期
     *
     * @param callback
     * @param productId
     * @return
     */
    @RequestMapping("findSecondDateByProductId")
    @ResponseBody
    public JSONPObject findSecondDateByProductId(String callback, Long productId) {
        return new JSONPObject(callback, ygProductSecondService.findUnEndByPid(productId));
    }

}
